package system

import (
	"context"
	"gf-admin/internal/consts"
	"gf-admin/internal/service"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/util/gconv"

	"gf-admin/api/system/v1"
)

func (c *ControllerV1) SysUserLogout(ctx context.Context, req *v1.SysUserLogoutReq) (res *v1.SysUserLogoutRes, errs error) {
	err, u := service.CtxInfo().GetUserInfo(ctx)
	if err != nil {
		return nil, err
	}

	//登出销毁Token
	err2 := consts.ApiToken.Destroy(ctx, gconv.String(u.Id))
	if err2 != nil {
		return nil, gerror.New("退出登录失败:" + err2.Error())
	}
	return nil, nil
}
